//
//  AnswerDetailViewController.m
//  jinnengExam
//
//  Created by mac on 2020/8/12.
//  Copyright © 2020 jznrj. All rights reserved.
//

#import "AnswerDetailViewController.h"
#import "QuestionDetailView.h"
@interface AnswerDetailViewController ()<OperateBarDelegate>
@property(nonatomic,strong) QuestionDetailView *bottomView;
@end

@implementation AnswerDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initView];
    self.title =@"答题详情";
    [self registerJSFunction];
}

-(void) viewWillAppear:(BOOL)animated{
    self.tabBarController.tabBar.frame = CGRectMake(0, 0, 0, 0);
    self.tabBarController.tabBar.hidden = YES;
}


-(void) initView{
    [self.view addSubview:self.jznWebView];
    self.jznWebView.scrollView.bounces = NO;
    [self.jznWebView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        if (@available(iOS 11.0, *)) {
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
        } else {
            make.top.equalTo(self.view);
        }
        make.bottom.equalTo(self.view).offset(-52);
    }];

    
    self.bottomView = [[QuestionDetailView alloc]init];
    self.bottomView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
    self.bottomView.delegate = self;
    [self.view addSubview:self.bottomView];
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
       if (@available(iOS 11.0, *)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
        } else {
            make.bottom.equalTo(self.view);
        }
        make.width.equalTo(self.view);
        make.height.equalTo(@52);
    }];
    [self.view addSubview:self.bottomView];
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self.jznWebView loadLocalFile:@"/ios_jinneng/answerDetail" type:@"html"];
    
}

- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation{
    NSString *js = [NSString stringWithFormat:@"loadPaper(%@)",self.paper];
    [self.jznWebView evaluateJavaScript:js completionHandler:nil];
    
    NSString *loadQuestion = [NSString stringWithFormat:@"loadQuestion(%d)",self.loadingIndex];
    [self.jznWebView evaluateJavaScript:loadQuestion completionHandler:nil];
}

-(void) registerJSFunction{
    [self.webViewBridge registerHandler:@"indexError" handler:^(id data, WVJBResponseCallback responseCallback) {
        NSString *error = data[@"errorMessage"];
        dispatch_async(dispatch_get_main_queue(), ^(){
            [[UIApplication sharedApplication].delegate.window makeToast:error];
        });
    }];

}

- (void)onButtonAction:(NSInteger)offset{
      if (offset == 0) {
          
          NSString *pre = @"pre()";
          [self.jznWebView evaluateJavaScript:pre completionHandler:nil];
      }else if(offset == 1){
          
          NSString *next = @"next()";
          [self.jznWebView evaluateJavaScript:next completionHandler:nil];
          
      }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
